<?php  
	include('./db/dbconn.php');
	if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
		$list_id = $_POST['list_id'];
		$list_data = $_POST['list_data'];
		$list_name = $_POST['list_name'];
		$list_time = $_POST['list_time'];
		
		$sql = "select comm_replay, comm_replay_name, comm_replay_time from comments where comm_id='$list_id'";
		$dd = "";
		$l_time = "";
		$l_name = "";
		$check_query = mysqli_query($conn, $sql);
		if ($result = mysqli_fetch_array($check_query)) {
			$d = $result['comm_replay'];
			$dd = iconv('gbk', 'utf-8', $d);
			
			$name = $result['comm_replay_name'];
			$l_name = iconv('gbk', 'utf-8', $name);
			
			$time = $result['comm_replay_time'];
			$l_time = iconv('gbk', 'utf-8', $time);
		}
		if ($dd != "") {
			$data = $dd.",".$list_data;
			$data_name = $l_name.",".$list_name;
			$data_time = $l_time.",".$list_time;
		} else {
			$data = $list_data;
			$data_name = $list_name;
			$data_time = $list_time;
		}
		
		$data = iconv('utf-8', 'gbk', $data);
		$data_name = iconv('utf-8', 'gbk', $data_name);
		$data_time = iconv('utf-8', 'gbk', $data_time);
		$sql = "update comments set comm_replay = '$data', comm_replay_name = '$data_name', comm_replay_time = '$data_time' where comm_id='$list_id'";
		mysqli_query($conn, $sql);
		
		$json = array("status" => "success", "data" => "$list_id", "content" => "$list_data");
		echo json_encode($json);
	} else {
		$json_err = array("status" => "fail");
		echo json_encode($json_err);
	}
?>  